<!doctype html>

<html lang="zh-CN" data-content_root="">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta
      name="generator"
      content="Docutils 0.17.1: http://docutils.sourceforge.net/"
    />

    <title>
      7. 使用矩阵计算岭回归系数 &#8212; 动手实战人工智能 AI By Doing
    </title>
    <script src="https://unpkg.com/@popperjs/core@2.9.2/dist/umd/popper.min.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="https://unpkg.com/tippy.js@6.3.1/dist/tippy-bundle.umd.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>

    <script type="9682b900fcd474fbe335b27c-text/javascript">
      MathJax = {
        loader: { load: ["[tex]/boldsymbol", "[tex]/textmacros"] },
        tex: {
          packages: { "[+]": ["boldsymbol", "textmacros"] },
          inlineMath: [
            ["$", "$"],
            ["\\(", "\\)"],
          ],
          processEscapes: true,
          macros: {
            argmax: "arg\\,max",
            argmin: "arg\\,min",
            col: "col",
            Span: "span",
            epsilon: "\\varepsilon",
            EE: "\\mathbb{E}",
            PP: "\\mathbb{P}",
            RR: "\\mathbb{R}",
            NN: "\\mathbb{N}",
            ZZ: "\\mathbb{Z}",
            aA: "\\mathcal{A}",
            bB: "\\mathcal{B}",
            cC: "\\mathcal{C}",
            dD: "\\mathcal{D}",
            eE: "\\mathcal{E}",
            fF: "\\mathcal{F}",
            gG: "\\mathcal{G}",
            hH: "\\mathcal{H}",
          },
        },
        svg: {
          fontCache: "global",
          scale: 0.92,
          displayAlign: "center",
        },
      };
    </script>

    <script data-cfasync="false">
      document.documentElement.dataset.mode =
        localStorage.getItem("mode") || "";
      document.documentElement.dataset.theme =
        localStorage.getItem("theme") || "";
    </script>

    <!-- Loaded before other Sphinx assets -->
    <link
      href="../_static/styles/theme.css?digest=dfe6caa3a7d634c4db9b"
      rel="stylesheet"
    />
    <link
      href="../_static/styles/bootstrap.css?digest=dfe6caa3a7d634c4db9b"
      rel="stylesheet"
    />
    <link
      href="../_static/styles/pydata-sphinx-theme.css?digest=dfe6caa3a7d634c4db9b"
      rel="stylesheet"
    />

    <link
      href="../_static/vendor/fontawesome/6.5.2/css/all.min.css?digest=dfe6caa3a7d634c4db9b"
      rel="stylesheet"
    />
    <link
      rel="preload"
      as="font"
      type="font/woff2"
      crossorigin
      href="../_static/vendor/fontawesome/6.5.2/webfonts/fa-solid-900.woff2"
    />
    <link
      rel="preload"
      as="font"
      type="font/woff2"
      crossorigin
      href="../_static/vendor/fontawesome/6.5.2/webfonts/fa-brands-400.woff2"
    />
    <link
      rel="preload"
      as="font"
      type="font/woff2"
      crossorigin
      href="../_static/vendor/fontawesome/6.5.2/webfonts/fa-regular-400.woff2"
    />

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link
      rel="stylesheet"
      href="../_static/styles/quantecon-book-theme.css?digest=bf319bfb28f1a534708d8469c2dff3b07f43ed05"
      type="text/css"
    />
    <link rel="stylesheet" type="text/css" href="../_static/togglebutton.css" />
    <link rel="stylesheet" type="text/css" href="../_static/copybutton.css" />
    <link
      rel="stylesheet"
      type="text/css"
      href="../_static/mystnb.4510f1fc1dee50b3e5859aac5469c37c29e427902b24a333a5f9fcb2f0b3ac41.css"
    />
    <link rel="stylesheet" type="text/css" href="../_static/sphinx-thebe.css" />
    <link rel="stylesheet" type="text/css" href="../_static/exercise.css" />
    <link rel="stylesheet" type="text/css" href="../_static/proof.css" />
    <link
      rel="stylesheet"
      type="text/css"
      href="../_static/sphinx-design.4cbf315f70debaebd550c87a6162cf0f.min.css"
    />

    <!-- Pre-loaded scripts that we'll load fully later -->
    <link
      rel="preload"
      as="script"
      href="../_static/scripts/bootstrap.js?digest=dfe6caa3a7d634c4db9b"
    />
    <link
      rel="preload"
      as="script"
      href="../_static/scripts/pydata-sphinx-theme.js?digest=dfe6caa3a7d634c4db9b"
    />
    <script src="../_static/vendor/fontawesome/6.5.2/js/all.min.js?digest=dfe6caa3a7d634c4db9b" type="9682b900fcd474fbe335b27c-text/javascript"></script>

    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/jquery.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/underscore.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/_sphinx_javascript_frameworks_compat.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/doctools.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/sphinx_highlight.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/clipboard.min.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/copybutton.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/scripts/sphinx-book-theme.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script type="9682b900fcd474fbe335b27c-text/javascript">
      let toggleHintShow = "点击显示";
    </script>
    <script type="9682b900fcd474fbe335b27c-text/javascript">
      let toggleHintHide = "点击隐藏";
    </script>
    <script type="9682b900fcd474fbe335b27c-text/javascript">
      let toggleOpenOnPrint = "true";
    </script>
    <script src="../_static/togglebutton.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="../_static/scripts/quantecon-book-theme.js?digest=d39fccd6699928d7d12b10e448e985dfabe24f14" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script type="9682b900fcd474fbe335b27c-text/javascript">
      var togglebuttonSelector = ".toggle, .admonition.dropdown";
    </script>
    <script src="../_static/design-tabs.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script type="9682b900fcd474fbe335b27c-text/javascript">
      const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
      const thebe_selector = ".thebe,.cell";
      const thebe_selector_input = "pre";
      const thebe_selector_output = ".output, .cell_output";
    </script>
    <script async="async" src="../_static/sphinx-thebe.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script type="9682b900fcd474fbe335b27c-text/javascript">
      window.MathJax = {
        options: {
          processHtmlClass: "tex2jax_process|mathjax_process|math|output_area",
        },
      };
    </script>
    <script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script type="9682b900fcd474fbe335b27c-text/javascript">
      DOCUMENTATION_OPTIONS.pagename =
        "notebooks/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations";
    </script>
    <link rel="shortcut icon" href="../_static/logo.png" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link
      rel="next"
      title="8. 回归模型评价与检验"
      href="chapter01-08-lab-evaluation-and-validation-of-regression-models.html"
    />
    <link
      rel="prev"
      title="6. 岭回归和 LASSO 回归实现"
      href="chapter01-06-lab-implementation-of-ridge-regression-and-lasso-regression.html"
    />

    <!-- Normal Meta Tags -->
    <meta name="author" context="huhuhang" />
    <meta
      name="keywords"
      content="矩阵计算，岭回归，机器学习教程，Python,scikit-learn"
    />
    <meta
      name="description"
      content="本教程详细讲解了如何使用 Python 矩阵计算岭回归系数，并与 scikit-learn 的计算结果进行对比，为读者提供了一个全面的机器学习实战训练。"
    />
    <link
      rel="canonical"
      href="https://aibydoing.com/notebooks/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations"
    />

    <!-- sitemap -->
    <link
      rel="sitemap"
      type="application/xml"
      title="Sitemap"
      href="https://aibydoing.com/sitemap.xml"
    />

    <!-- Twitter tags -->
    <meta name="twitter:card" content="summary_large_image" />
    <meta name="twitter:site" content="@huhuhang" />
    <meta name="twitter:title" content="使用矩阵计算岭回归系数" />
    <meta
      name="twitter:description"
      content="使用矩阵计算岭回归系数  介绍  前面的实验中，我们学习了岭回归和 LASSO 回归方法，并使用 scikit-learn 对两种方法进行了实战训练。本次挑战中，我们将尝试直接使用 Python 完成岭回归系数 w 计算，并与 scikit-learn 计算结果进行比较。  知识点  使用 Python 计算岭回归系数"
    />
    <meta name="twitter:creator" content="@huhuhang" />
    <meta
      name="twitter:image"
      content="https://cdn.aibydoing.com/aibydoing/covers/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations.png"
    />

    <!-- Opengraph tags -->
    <meta property="og:title" content="使用矩阵计算岭回归系数" />
    <meta property="og:type" content="article" />
    <meta
      property="og:url"
      content="https://aibydoing.com/notebooks/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations"
    />
    <meta
      property="og:image"
      content="https://cdn.aibydoing.com/aibydoing/covers/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations.png"
    />
    <meta
      property="og:description"
      content="使用矩阵计算岭回归系数  介绍  前面的实验中，我们学习了岭回归和 LASSO 回归方法，并使用 scikit-learn 对两种方法进行了实战训练。本次挑战中，我们将尝试直接使用 Python 完成岭回归系数 w 计算，并与 scikit-learn 计算结果进行比较。  知识点  使用 Python 计算岭回归系数"
    />
    <meta property="og:site_name" content="动手实战人工智能 AI By Doing" />
    <meta name="theme-color" content="#ffffff" />

    <!-- Adsense -->
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5114745371732676" crossorigin="anonymous" type="9682b900fcd474fbe335b27c-text/javascript"></script>

    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-NMNTKKG9WB" type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script type="9682b900fcd474fbe335b27c-text/javascript">
      window.dataLayer = window.dataLayer || [];
      function gtag() {
        dataLayer.push(arguments);
      }
      gtag("js", new Date());

      gtag("config", "G-NMNTKKG9WB");
    </script>
  </head>
  <body>
    <span id="top"></span>

    <div class="qe-wrapper">
      <div class="qe-main">
        <div
          class="qe-page"
          id="notebooks/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations"
        >
          <div class="qe-page__toc">
            <div class="inner">
              <div class="qe-page__toc-header alert alert-light">
                <nav id="bd-toc-nav" class="qe-page__toc-nav">
                  <ul class="visible nav section-nav flex-column">
                    <li class="toc-h2 nav-item toc-entry">
                      <a class="reference internal nav-link" href="#id2"
                        >7.1. 介绍</a
                      >
                    </li>
                    <li class="toc-h2 nav-item toc-entry">
                      <a class="reference internal nav-link" href="#id3"
                        >7.2. 知识点</a
                      >
                    </li>
                    <li class="toc-h2 nav-item toc-entry">
                      <a class="reference internal nav-link" href="#python"
                        >7.3. 使用 Python 计算岭回归系数</a
                      >
                    </li>
                    <li class="toc-h2 nav-item toc-entry">
                      <a
                        class="reference internal nav-link"
                        href="#scikit-learn"
                        >7.4. 使用 scikit-learn 计算岭回归系数</a
                      >
                    </li>
                  </ul>
                </nav>
              </div>
              <div class="qe-page__toc-footer">
                <div class="d-grid gap-2">
                  <a href="#top">
                    <button
                      class="btn btn-light alert alert-light"
                      style="width: 100%; margin: 0"
                      type="button"
                    >
                      <i class="fa-solid fa-circle-arrow-up"></i> 返回顶部
                    </button>
                  </a>
                </div>
              </div>
            </div>
          </div>
          <div class="qe-page__header alert alert-light">
            <div class="qe-page__header-copy">
              <p class="qe-page__header-heading">
                <a href="../intro.html">动手实战人工智能 AI By Doing</a>
              </p>
              <p class="qe-page__header-subheading">
                <a
                  href="https://aibydoing.com/notebooks/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations"
                  >使用矩阵计算岭回归系数</a
                >
              </p>
            </div>
            <p class="qe-page__header-authors">
              <a href="https://huhuhang.com" target="_blank">huhuhang</a>
              更新于：2024-08-31 12:05:12
            </p>
          </div>
          <!-- .page__header -->

          <main class="qe-page__content" role="main">
            <div
              class="alert alert-light"
              style="padding: unset"
              data-tilt
              data-tilt-max="5"
              data-tilt-speed="300"
              data-tilt-perspective="1000"
              data-tilt-glare
              data-tilt-max-glare="0.2"
            >
              <img
                alt="cover"
                style="border-radius: 0.375rem"
                src="https://cdn.aibydoing.com/aibydoing/covers/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations.png"
              />
            </div>
            <div
              class="alert alert-light"
              style="padding: unset"
              data-tilt
              data-tilt-max="5"
              data-tilt-speed="300"
              data-tilt-perspective="1000"
              data-tilt-glare
              data-tilt-max-glare="0.2"
            >
              <a href="https://pro.aibydoing.com"
                ><div class="card custom-card">
                  <div class="card-body">
                    <div style="display: flex; align-items: center">
                      <img
                        src="https://cdn.aibydoing.com/aibydoing/images/aibydoing-pro-icon.svg"
                        alt="Pro 计划"
                        style="width: 128px"
                      />
                      <div style="margin-left: 20px">
                        <h4 class="card-title mt-3">Pro 会员计划</h4>
                        <p class="card-text">
                          Pro
                          计划是作者为了维护和更新本教程而推出的会员计划，你可以获得更多的福利和服务，点击查看详情。
                        </p>
                      </div>
                    </div>
                  </div>
                </div></a
              >
            </div>

            <div class="main-content alert alert-light">
              <section class="tex2jax_ignore mathjax_ignore" id="id1">
                <h1>
                  <span class="section-number">7. </span
                  >使用矩阵计算岭回归系数<a
                    class="headerlink"
                    href="#id1"
                    title="Permalink to this heading"
                    >#</a
                  >
                </h1>
                <section id="id2">
                  <h2>
                    <span class="section-number">7.1. </span>介绍<a
                      class="headerlink"
                      href="#id2"
                      title="Permalink to this heading"
                      >#</a
                    >
                  </h2>
                  <p>
                    前面的实验中，我们学习了岭回归和 LASSO 回归方法，并使用
                    scikit-learn
                    对两种方法进行了实战训练。本次挑战中，我们将尝试直接使用
                    Python 完成岭回归系数
                    <span class="math notranslate nohighlight">\(w\)</span>
                    计算，并与 scikit-learn 计算结果进行比较。
                  </p>
                </section>
                <section id="id3">
                  <h2>
                    <span class="section-number">7.2. </span>知识点<a
                      class="headerlink"
                      href="#id3"
                      title="Permalink to this heading"
                      >#</a
                    >
                  </h2>
                  <ul class="simple">
                    <li><p>使用 Python 计算岭回归系数</p></li>
                    <li><p>使用 scikit-learn 计算岭回归系数</p></li>
                  </ul>
                </section>
                <section id="python">
                  <h2>
                    <span class="section-number">7.3. </span>使用 Python
                    计算岭回归系数<a
                      class="headerlink"
                      href="#python"
                      title="Permalink to this heading"
                      >#</a
                    >
                  </h2>
                  <p>前面的课程中，我们已经知道了岭回归的向量表达式：</p>
                  <div class="math notranslate nohighlight">
                    \[ F_{R i d g e}=\|y-X w\|_{2}^{2}+\lambda\|w\|_{2}^{2}
                    \tag{1} \]
                  </div>
                  <p>以及该向量表达式的解析解：</p>
                  <div class="math notranslate nohighlight">
                    \[\hat w_{Ridge} = (X^TX + \lambda I)^{-1} X^TY \tag{2}\]
                  </div>
                  <div class="exercise admonition" id="chapter01_07_1">
                    <p class="admonition-title">
                      <span class="caption-number">Exercise 7.1 </span>
                    </p>
                    <section id="exercise-content">
                      <p>
                        挑战：参考公式
                        <span class="math notranslate nohighlight"
                          >\((2)\)</span
                        >
                        ，完成 Python 实现岭回归系数
                        <span class="math notranslate nohighlight">\(w\)</span>
                        的计算函数。
                      </p>
                      <p>
                        提示：使用
                        <code class="docutils literal notranslate"
                          ><span class="pre">np.eye()</span></code
                        >
                        生成单位矩阵，并注意公式是矩阵乘法。
                      </p>
                    </section>
                  </div>
                  <div class="cell docutils container">
                    <div class="cell_input docutils container">
                      <div class="highlight-ipython3 notranslate">
                        <div class="highlight">
                          <pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>

<span class="k">def</span><span class="w"> </span><span class="nf">ridge_regression</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">alpha</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    参数:</span>
<span class="sd">    X -- 自变量数据矩阵</span>
<span class="sd">    Y -- 因变量数据矩阵</span>
<span class="sd">    alpha -- lamda 参数</span>

<span class="sd">    返回:</span>
<span class="sd">    W -- 岭回归系数</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="c1">### 代码开始 ### (≈ 3 行代码)</span>

    <span class="c1">### 代码结束 ###</span>
    
    <span class="k">return</span> <span class="n">W</span>
</pre>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div
                    class="solution dropdown admonition"
                    id="notebooks/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations-solution-1"
                  >
                    <p class="admonition-title">
                      参考答案<a
                        class="reference internal"
                        href="#chapter01_07_1"
                      >
                        Exercise 7.1</a
                      >
                    </p>
                    <section id="solution-content">
                      <div class="highlight-python notranslate">
                        <div class="highlight">
                          <pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>

<span class="k">def</span><span class="w"> </span><span class="nf">ridge_regression</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">alpha</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    参数:</span>
<span class="sd">    X -- 自变量数据矩阵</span>
<span class="sd">    Y -- 因变量数据矩阵</span>
<span class="sd">    alpha -- lamda 参数</span>

<span class="sd">    返回:</span>
<span class="sd">    W -- 岭回归系数</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="c1">### 代码开始 ### (≈ 3 行代码)</span>
    <span class="n">XTX</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">T</span> <span class="o">*</span> <span class="n">X</span>
    <span class="n">reg</span> <span class="o">=</span> <span class="n">XTX</span> <span class="o">+</span> <span class="n">alpha</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
    <span class="n">W</span> <span class="o">=</span> <span class="n">reg</span><span class="o">.</span><span class="n">I</span> <span class="o">*</span> <span class="p">(</span><span class="n">X</span><span class="o">.</span><span class="n">T</span> <span class="o">*</span> <span class="n">Y</span><span class="p">)</span> 
    <span class="c1">### 代码结束 ###</span>
    
    <span class="k">return</span> <span class="n">W</span>
</pre>
                        </div>
                      </div>
                    </section>
                  </div>
                  <p>下面，我们生成测试数据：</p>
                  <div class="cell docutils container">
                    <div class="cell_input docutils container">
                      <div class="highlight-ipython3 notranslate">
                        <div class="highlight">
                          <pre><span></span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="c1"># 设置随机数种子</span>

<span class="n">X</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)))</span>
<span class="n">Y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">1</span> <span class="p">)))</span>
<span class="n">alpha</span> <span class="o">=</span> <span class="mf">0.5</span>
</pre>
                        </div>
                      </div>
                    </div>
                  </div>
                  <p>运行测试</p>
                  <p>
                    计算岭回归系数<span class="math notranslate nohighlight"
                      >\(w\)</span
                    >的值：
                  </p>
                  <div class="cell docutils container">
                    <div class="cell_input docutils container">
                      <div class="highlight-ipython3 notranslate">
                        <div class="highlight">
                          <pre><span></span><span class="n">ridge_regression</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">alpha</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
</pre>
                        </div>
                      </div>
                    </div>
                  </div>
                  <p>期望输出</p>
                  <div class="highlight-python notranslate">
                    <div class="highlight">
                      <pre><span></span><span class="n">matrix</span><span class="p">([[</span> <span class="mf">1.42278923</span><span class="p">,</span>  <span class="mf">2.20583559</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.6391644</span> <span class="p">,</span>  <span class="mf">0.64022529</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.44014758</span><span class="p">,</span>
          <span class="mf">1.66307858</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.83879894</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.25611354</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.06951638</span><span class="p">,</span> <span class="o">-</span><span class="mf">2.56882017</span><span class="p">]])</span>
</pre>
                    </div>
                  </div>
                </section>
                <section id="scikit-learn">
                  <h2>
                    <span class="section-number">7.4. </span>使用 scikit-learn
                    计算岭回归系数<a
                      class="headerlink"
                      href="#scikit-learn"
                      title="Permalink to this heading"
                      >#</a
                    >
                  </h2>
                  <p>
                    上面的挑战中，你已经学会了使用 Python 计算岭回归系数
                    <span class="math notranslate nohighlight">\(w\)</span
                    >。下面，我们看一看结果是否与 scikit-learn 的计算结果一致。
                  </p>
                  <div class="exercise admonition" id="chapter01_07_2">
                    <p class="admonition-title">
                      <span class="caption-number">Exercise 7.2 </span>
                    </p>
                    <section id="exercise-content">
                      <p>
                        挑战：使用 scikit-learn 计算岭回归系数
                        <span class="math notranslate nohighlight">\(w\)</span
                        >。
                      </p>
                      <p>
                        提示：请向岭回归模型中增加
                        <code class="docutils literal notranslate"
                          ><span class="pre">fit_intercept=False</span></code
                        >
                        参数取消截距。
                      </p>
                    </section>
                  </div>
                  <div class="cell docutils container">
                    <div class="cell_input docutils container">
                      <div class="highlight-ipython3 notranslate">
                        <div class="highlight">
                          <pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">sklearn.linear_model</span><span class="w"> </span><span class="kn">import</span> <span class="n">Ridge</span>

<span class="k">def</span><span class="w"> </span><span class="nf">ridge_model</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">alpha</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    参数:</span>
<span class="sd">    X -- 自变量数据矩阵</span>
<span class="sd">    Y -- 因变量数据矩阵</span>
<span class="sd">    alpha -- lamda 参数</span>

<span class="sd">    返回:</span>
<span class="sd">    W -- 岭回归系数</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="c1">### 代码开始 ### (≈ 3 行代码)</span>

    <span class="c1">### 代码结束 ###</span>
    
    <span class="k">return</span> <span class="n">W</span>
</pre>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div
                    class="solution dropdown admonition"
                    id="notebooks/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations-solution-3"
                  >
                    <p class="admonition-title">
                      参考答案<a
                        class="reference internal"
                        href="#chapter01_07_2"
                      >
                        Exercise 7.2</a
                      >
                    </p>
                    <section id="solution-content">
                      <div class="highlight-python notranslate">
                        <div class="highlight">
                          <pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">sklearn.linear_model</span><span class="w"> </span><span class="kn">import</span> <span class="n">Ridge</span>

<span class="k">def</span><span class="w"> </span><span class="nf">ridge_model</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">alpha</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    参数:</span>
<span class="sd">    X -- 自变量数据矩阵</span>
<span class="sd">    Y -- 因变量数据矩阵</span>
<span class="sd">    alpha -- lamda 参数</span>

<span class="sd">    返回:</span>
<span class="sd">    W -- 岭回归系数</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="c1">### 代码开始 ### (≈ 3 行代码)</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Ridge</span><span class="p">(</span><span class="n">alpha</span><span class="p">,</span> <span class="n">fit_intercept</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
    <span class="n">model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X</span><span class="p">,</span><span class="n">Y</span><span class="p">)</span>
    <span class="n">W</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">coef_</span>
    <span class="c1">### 代码结束 ###</span>
    
    <span class="k">return</span> <span class="n">W</span>
</pre>
                        </div>
                      </div>
                    </section>
                  </div>
                  <p>运行测试</p>
                  <p>
                    计算岭回归系数
                    <span class="math notranslate nohighlight">\(w\)</span>
                    的值：
                  </p>
                  <div class="cell docutils container">
                    <div class="cell_input docutils container">
                      <div class="highlight-ipython3 notranslate">
                        <div class="highlight">
                          <pre><span></span><span class="n">ridge_model</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">Y</span><span class="p">,</span> <span class="n">alpha</span><span class="p">)</span>
</pre>
                        </div>
                      </div>
                    </div>
                  </div>
                  <p>期望输出</p>
                  <div class="highlight-python notranslate">
                    <div class="highlight">
                      <pre><span></span><span class="n">matrix</span><span class="p">([[</span> <span class="mf">1.42278923</span><span class="p">,</span>  <span class="mf">2.20583559</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.6391644</span> <span class="p">,</span>  <span class="mf">0.64022529</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.44014758</span><span class="p">,</span>
          <span class="mf">1.66307858</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.83879894</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.25611354</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.06951638</span><span class="p">,</span> <span class="o">-</span><span class="mf">2.56882017</span><span class="p">]])</span>
</pre>
                    </div>
                  </div>
                  <p>
                    我们可以看到，和预想的一致，两种方法计算出的
                    <span class="math notranslate nohighlight">\(w\)</span>
                    系数值是一模一样的。
                  </p>
                </section>
              </section>

              <script type="text/x-thebe-config">
                {
                    requestKernel: true,
                    binderOptions: {
                        repo: "binder-examples/jupyter-stacks-datascience",
                        ref: "master",
                    },
                    codeMirrorConfig: {
                        theme: "abcdef",
                        mode: "python"
                    },
                    kernelOptions: {
                        name: "python3",
                        path: "./notebooks"
                    },
                    predefinedOutput: true
                }
              </script>
              <script type="9682b900fcd474fbe335b27c-text/javascript">
                kernelName = "python3";
              </script>

              <hr />
              <!-- share tips -->
              <p
                style="
                  font-size: 13px;
                  display: inline-block;
                  color: #555;
                  margin: unset;
                "
              >
                ○ 欢迎分享<a
                  href="https://aibydoing.com/notebooks/chapter01-07-challenge-computing-ridge-regression-coefficients-with-matrix-operations"
                  >本文链接</a
                >到你的社交账号、博客、论坛等。更多的外链会增加搜索引擎对本站收录的权重，从而让更多人看到这些内容。
              </p>
              <!-- share tips -->
            </div>

            <!-- buymecoffee -->
            <div class="buymecoffee alert" role="alert">
              <p>
                如果你觉得这些内容对你有帮助，可以
                <a class="reference external" href="/buy-me-a-coffee"
                  >请我喝杯咖啡 <i class="fa-solid fa-mug-hot"></i
                ></a>
              </p>
            </div>
            <!-- buymecoffee -->
            <div class="prev-next-area alert alert-light">
              <a
                class="left-prev"
                href="chapter01-06-lab-implementation-of-ridge-regression-and-lasso-regression.html"
                title="previous page"
              >
                <i class="fa-solid fa-angle-left"></i>
                <div class="prev-next-info">
                  <p class="prev-next-subtitle">上一章</p>
                  <p class="prev-next-title">
                    <span class="section-number">6. </span>岭回归和 LASSO
                    回归实现
                  </p>
                </div>
              </a>
              <a
                class="right-next"
                href="chapter01-08-lab-evaluation-and-validation-of-regression-models.html"
                title="next page"
              >
                <div class="prev-next-info">
                  <p class="prev-next-subtitle">下一章</p>
                  <p class="prev-next-title">
                    <span class="section-number">8. </span>回归模型评价与检验
                  </p>
                </div>
                <i class="fa-solid fa-angle-right"></i>
              </a>
            </div>
            <div class="giscus alert alert-light"></div>
          </main>
          <!-- .page__content -->

          <footer class="qe-page__footer">
            <p xmlns:cc="http://creativecommons.org/ns#">
              本作品由
              <a href="https://huhuhang.com" target="_blank">huhuhang</a>
              创作，采用
              <a
                href="https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh-hans"
                target="_blank"
                rel="license noopener noreferrer"
                style="display: inline-block"
                >署名-非商业性使用-禁止演绎 4.0 国际</a
              >
              及
              <a
                href="https://aibydoing.com/intro#id2"
                target="_blank"
                rel="license noopener noreferrer"
                style="display: inline-block"
                >补充许可协议</a
              >
            </p>
          </footer>
          <!-- .page__footer -->
        </div>
        <!-- .page -->

        <div
          class="qe-sidebar bd-sidebar inactive persistent"
          id="site-navigation"
        >
          <div class="qe-sidebar__header">目录</div>

          <nav
            class="qe-sidebar__nav"
            id="qe-sidebar-nav"
            aria-label="Main navigation"
          >
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a class="reference internal" href="../lab-env.html">
                  环境说明
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 监督学习：回归 </span>
            </p>
            <ul class="current nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter01-01-lab-machine-learning-overview-and-examples.html"
                >
                  1. 机器学习综述及示例
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter01-02-lab-linear-regression-implementation-and-applications.html"
                >
                  2. 线性回归实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter01-03-challenge-housing-price-prediction-in-beijing.html"
                >
                  3. 北京市住房价格预测
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter01-04-lab-polynomial-regression-implementation-and-applications.html"
                >
                  4. 多项式回归实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter01-05-challenge-bitcoin-price-prediction-and-visualization.html"
                >
                  5. 比特币价格预测及绘图
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter01-06-lab-implementation-of-ridge-regression-and-lasso-regression.html"
                >
                  6. 岭回归和 LASSO 回归实现
                </a>
              </li>
              <li class="toctree-l1 current active active">
                <a class="current reference internal" href="#">
                  7. 使用矩阵计算岭回归系数
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter01-08-lab-evaluation-and-validation-of-regression-models.html"
                >
                  8. 回归模型评价与检验
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter01-09-challenge-comprehensive-practical-application-of-regression-methods.html"
                >
                  9. 回归方法综合应用练习
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 监督学习：分类 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-01-lab-logistic-regression-implementation-and-applications.html"
                >
                  10. 逻辑回归实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-02-challenge-gradient-descent-method-implementation-and-applications.html"
                >
                  11. 梯度下降法实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-03-lab-implementation-and-applications-of-the-k-nearest-neighbors-algorithm.html"
                >
                  12. K 近邻算法实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-04-challenge-implementation-and-application-of-k-nearest-neighbors-regression-algorithm.html"
                >
                  13. K 近邻回归算法实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-05-lab-naive-bayes-implementation-and-applications.html"
                >
                  14. 朴素贝叶斯实现及应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-06-challenge-implementation-and-visualization-of-the-gaussian-distribution-function.html"
                >
                  15. 高斯分布函数实现及绘图
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-07-lab-evaluation-methods-for-classification-models.html"
                >
                  16. 分类模型评价方法
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-08-lab-support-vector-machines-implementation-and-applications.html"
                >
                  17. 支持向量机实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-09-challenge-support-vector-machine-for-human-portrait-classification.html"
                >
                  18. 支持向量机实现人像分类
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-10-lab-decision-tree-implementation-and-applications.html"
                >
                  19. 决策树实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-11-challenge-optimization-and-selection-of-decision-tree-model-parameters.html"
                >
                  20. 决策树模型参数优化及选择
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-12-lab-integrated-learning-method-for-bagging-and-boosting.html"
                >
                  21. 装袋和提升集成学习方法
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-13-challenge-application-of-heterogeneous-ensemble-voting-methods.html"
                >
                  22. 异质集成投票方法应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter02-14-challenge-model-selection-with-cross-validation.html"
                >
                  23. 使用交叉验证快速选择模型
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 无监督学习：聚类 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-01-lab-clustering-methods-implementation-and-applications.html"
                >
                  24. 划分聚类方法实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-02-challenge-image-compression-using-k-means-clustering.html"
                >
                  25. 使用 K-Means 完成图像压缩
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-03-lab-implementation-and-applications-of-hierarchical-clustering-methods.html"
                >
                  26. 层次聚类方法实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-04-lab-principle-and-applications-of-principal-component-analysis.html"
                >
                  27. 主成分分析原理及应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-05-challenge-hierarchical-clustering-applications-and-dendrogram-visualization.html"
                >
                  28. 层次聚类应用及聚类树绘制
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-06-lab-implementation-and-applications-of-density-based-clustering-algorithms.html"
                >
                  29. 密度聚类方法实现与应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-07-challenge-density-based-clustering-for-anomaly-detection-in-shared-bike-systems.html"
                >
                  30. 密度聚类标记异常共享单车
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-08-lab-application-of-spectral-clustering-and-other-clustering-methods.html"
                >
                  31. 谱聚类及其他聚类方法应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter03-09-challenge-comparative-evaluation-of-common-clustering-algorithms.html"
                >
                  32. 常用聚类算法对比评估
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 无监督学习：关联规则 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter04-01-lab-apriori-association-rule-learning-algorithm.html"
                >
                  33. Apriori 关联规则学习方法
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter04-02-challenge-analysis-of-association-rules-in-shopping-data.html"
                >
                  34. 购物数据关联规则分析
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter04-03-lab-time-series-data-analysis-and-processing.html"
                >
                  35. 时间序列数据分析处理
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter04-04-challenge-stock-time-series-data-processing.html"
                >
                  36. 股票时间序列数据处理
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter04-05-lab-modelling-and-analysis-of-time-series-data.html"
                >
                  37. 时间序列数据建模分析
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter04-06-challenge-modeling-and-analysis-of-agricultural-production-index.html"
                >
                  38. 农业生产指数建模分析
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 机器学习工程：模型部署和推理 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter05-01-lab-a-comprehensive-review-of-automated-machine-learning.html"
                >
                  39. 自动化机器学习综述
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter05-02-lab-automated-machine-learning-practices-and-applications.html"
                >
                  40. 自动化机器学习实践应用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter05-03-challenge-automl-for-handwritten-character-classification.html"
                >
                  41. AutoML 完成手写字符分类
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter05-04-lab-machine-learning-model-inference-and-deployment.html"
                >
                  42. 机器学习模型推理与部署
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter05-05-challenge-mushroom-classification-model-deployment-and-inference.html"
                >
                  43. 蘑菇分类模型部署和推理
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter05-06-lab-dynamic-incremental-training-of-machine-learning-models.html"
                >
                  44. 机器学习模型动态增量训练
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter05-07-challenge-online-learning-and-cloud-model-deployment.html"
                >
                  45. 在线学习及云端模型部署
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 深度学习原理：人工神经网络 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter06-01-lab-a-concise-review-and-exemplification-of-deep-learning.html"
                >
                  46. 深度学习综述和示例
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter06-02-lab-perceptron-and-artificial-neural-networks.html"
                >
                  47. 感知机和人工神经网络
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter06-03-challenge-handwritten-character-recognition-neural-network.html"
                >
                  48. 手写字符识别神经网络
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text">
                深度学习框架：TensorFlow &amp; PyTorch
              </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-01-lab-tensorflow-fundamentals-and-syntax.html"
                >
                  49. TensorFlow 基础概念语法
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-02-challenge-tensorflow-california-housing-price-prediction.html"
                >
                  50. TensorFlow 加州房价预测
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-03-lab-building-neural-networks-with-tensorflow.html"
                >
                  51. TensorFlow 构建神经网络
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-04-challenge-tensorflow-automotive-rating-classification.html"
                >
                  52. TensorFlow 汽车评估分类
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-05-lab-advanced-tensorflow-api-usage.html"
                >
                  53. TensorFlow 高阶 API 使用
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-06-challenge-tensorflow-fashion-item-classification.html"
                >
                  54. TensorFlow 时尚物品分类
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-07-lab-pytorch-fundamentals-and-syntax.html"
                >
                  55. PyTorch 基础概念语法
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-08-lab-building-neural-networks-with-pytorch.html"
                >
                  56. PyTorch 构建神经网络
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter07-09-challenge-linear-regression-implementation-with-pytorch.html"
                >
                  57. PyTorch 实现线性回归
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 深度学习应用：计算机视觉 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-01-lab-principles-of-convolutional-neural-networks.html"
                >
                  58. 卷积神经网络原理
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-02-lab-convolutional-neural-network-construction.html"
                >
                  59. 卷积神经网络构建
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-03-challenge-building-lenet5-estimator.html"
                >
                  60. 构建 LeNet-5 Estimator
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-04-lab-principles-and-practices-of-image-classification.html"
                >
                  61. 图像分类原理与实践
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-05-challenge-animal-classification-via-transfer-learning.html"
                >
                  62. 迁移学习完成动物分类
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-06-lab-principles-and-construction-of-generative-adversarial-networks.html"
                >
                  63. 生成对抗网络原理及构建
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-07-challenge-anime-character-image-generation-using-dcgan.html"
                >
                  64. DCGAN 动漫人物图像生成
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-08-lab-autoencoder-principles-and-construction.html"
                >
                  65. 自动编码器原理及构建
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-09-challenge-denoising-convolutional-autoencoders-for-image-denoising.html"
                >
                  66. 卷积自动编码器图像去噪
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-10-lab-principles-and-practices-of-object-detection.html"
                >
                  67. 目标检测原理与实践
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter08-11-challenge-yolo-image-object-detection-application.html"
                >
                  68. YOLO 图像目标检测应用
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 深度学习应用：自然语言处理 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter09-01-lab-principles-of-recurrent-neural-networks.html"
                >
                  69. 循环神经网络原理
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter09-02-lab-construction-of-recurrent-neural-networks.html"
                >
                  70. 循环神经网络构建
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter09-03-challenge-stock-price-prediction-with-lstm.html"
                >
                  71. LSTM 预测股票价格
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter09-04-lab-principles-and-practices-of-text-classification.html"
                >
                  72. 文本分类原理与实践
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter09-05-challenge-deep-learning-for-fake-news-classification.html"
                >
                  73. 深度学习完成假新闻分类
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter09-06-lab-extension-of-natural-language-processing-frameworks.html"
                >
                  74. 自然语言处理框架拓展
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter09-07-challenge-application-of-bert-pretraining-techniques.html"
                >
                  75. Google BERT 预训练技术
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter09-08-lab-neural-machine-translation-and-conversational-systems.html"
                >
                  76. 神经机器翻译和对话系统
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 深度学习工程：模型部署和推理 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter10-01-lab-a-concise-review-of-automated-deep-learning.html"
                >
                  77. 自动化深度学习综述
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter10-02-lab-automated-deep-learning-practice.html"
                >
                  78. 自动化深度学习实践
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter10-03-challenge-aerial-cactus-image-classification.html"
                >
                  79. 仙人掌航拍照片分类识别
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter10-04-lab-deep-learning-model-inference-and-deployment.html"
                >
                  80. 深度学习模型推理和部署
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter10-05-challenge-building-image-classification-inference-service.html"
                >
                  81. 构建图像分类推理服务
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter10-06-lab-deep-learning-cloud-service-practice.html"
                >
                  82. 深度学习云端服务实践
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter10-07-challenge-cloud-service-vat-invoice-recognition.html"
                >
                  83. 云服务识别增值税发票
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 强化学习基础 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter11-01-lab-introduction-and-examples-of-reinforcement-learning.html"
                >
                  84. 强化学习介绍与示例
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter11-02-lab-implementation-of-the-q-learning-reinforcement-learning-method.html"
                >
                  85. Q-Learning 强化学习方法实现
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="chapter11-03-challenge-implementing-the-sarsa-learning-algorithm-to-navigate-a-maze.html"
                >
                  86. 实现 Sarsa 学习算法走出迷宫
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 附录：机器学习数学基础 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix01-01-linear-algebra-with-python.html"
                >
                  87. Python 线性代数基础
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix01-02-calculus-with-python.html"
                >
                  88. Python 微积分基础
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix01-03-probability-theory-and-statistics-with-python.html"
                >
                  89. Python 概率论和统计学基础
                </a>
              </li>
            </ul>
            <p aria-level="2" class="caption" role="heading">
              <span class="caption-text"> 附录：机器学习常用工具 </span>
            </p>
            <ul class="nav bd-sidenav nav sidenav_l1">
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix02-00-jupyter-notebook-concise-guide.html"
                >
                  90. Jupyter Notebook 简明指南
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix02-01-numpy-basics-of-numeric-computing.html"
                >
                  91. NumPy 数值计算基础
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix02-02-basic-of-pandas-data-processing.html"
                >
                  92. Pandas 数据处理基础
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix02-03-method-of-drawing-2d-graphics-with-matplotlib.html"
                >
                  93. Matplotlib 二维图像绘制方法
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix02-04-method-of-drawing-3d-graphics-with-matplotlib.html"
                >
                  94. Matplotlib 三维图形绘制方法
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix02-05-introduction-to-seaborn-data-visualization-basics.html"
                >
                  95. Seaborn 数据可视化基础
                </a>
              </li>
              <li class="toctree-l1">
                <a
                  class="reference internal"
                  href="appendix02-06-basic-of-scientific-computing-with-scipy.html"
                >
                  96. SciPy 科学计算基础
                </a>
              </li>
            </ul>
          </nav>

          <div class="qe-sidebar__footer"></div>
        </div>
        <!-- .sidebar -->
      </div>
      <!-- .main -->

      <div class="qe-toolbar">
        <div class="qe-toolbar__inner">
          <ul class="qe-toolbar__main">
            <li data-tippy-content="目录" class="btn__sidebar">
              <i data-feather="menu"></i>
            </li>
            <li data-tippy-content="主页" class="btn__home">
              <a href="https://aibydoing.com"><i data-feather="home"></i></a>
            </li>
          </ul>

          <ul class="qe-toolbar__links">
            <li data-tippy-content="全屏" class="btn__fullscreen">
              <i data-feather="maximize"></i>
            </li>
            <li data-tippy-content="搜索" class="btn__search">
              <form action="../search.html" method="get">
                <input
                  type="search"
                  class="form-control"
                  name="q"
                  id="search-input"
                  placeholder="搜索"
                  aria-label="搜索"
                  autocomplete="off"
                  accesskey="k"
                />
                <i data-feather="search" id="search-icon"></i>
              </form>
            </li>
            <li data-tippy-content="增加字体大小" class="btn__plus">
              <i data-feather="plus-circle"></i>
            </li>
            <li data-tippy-content="减小字体大小" class="btn__minus">
              <i data-feather="minus-circle"></i>
            </li>
          </ul>
        </div>
      </div>
      <!-- .toolbar -->
    </div>
    <!-- .wrapper-->

    <script src="https://giscus.app/client.js" data-repo="aibydoing/feedback" data-repo-id="R_kgDOKrSOWw" data-category="General" data-category-id="DIC_kwDOKrSOW84CdVV4" data-mapping="og:title" data-strict="0" data-reactions-enabled="1" data-emit-metadata="0" data-input-position="top" data-theme="light" data-lang="zh-CN" data-loading="lazy" crossorigin="anonymous" async type="9682b900fcd474fbe335b27c-text/javascript"></script>
    <script src="https://aibydoing.com/_static/vanilla-tilt.min.js" type="9682b900fcd474fbe335b27c-text/javascript"></script>
  <script src="/cdn-cgi/scripts/7d0fa10a/cloudflare-static/rocket-loader.min.js" data-cf-settings="9682b900fcd474fbe335b27c-|49" defer></script></body>
</html>
